package com.mindspore.vision.ui;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;

import com.mindspore.vision.R;
import com.mindspore.vision.ui.adapter.ClassificationChildAdapter;
import com.mindspore.vision.ui.bean.ClassificationResultBean;

import java.util.ArrayList;
import java.util.List;

public class ClassificationChildFragment extends Fragment {

    private RecyclerView recyclerView;
    private List<ClassificationResultBean> dataList = new ArrayList<>();
    private ClassificationChildAdapter adapter;

    public static ClassificationChildFragment newInstance() {
        ClassificationChildFragment fragment = new ClassificationChildFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_classification_child_list, container, false);
        recyclerView = (RecyclerView) view;
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        adapter = new ClassificationChildAdapter(getContext(), dataList);
        recyclerView.setAdapter(adapter);
    }


    public void setDataList(List<ClassificationResultBean> dataList) {
        this.dataList.clear();
        this.dataList.addAll(dataList);
        adapter.notifyDataSetChanged();
    }
}